import Service.Impl.DistinguishServiceImpl;
import Service.Impl.MyChangeServiceImpl;
import Service.Impl.SystemRealServiceImpl;

import javax.swing.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        DistinguishServiceImpl distinguishService = new DistinguishServiceImpl();
        SystemRealServiceImpl systemRealService = new SystemRealServiceImpl();
        MyChangeServiceImpl myChangeService = new MyChangeServiceImpl();
        // 获取输入类型
        Object in;
        Scanner input = new Scanner(System.in);
        if(input.hasNextInt()){
            in = input.nextInt();
        } else if(input.hasNextFloat()){
            in = input.nextFloat();
        } else {
            String stringIn = input.nextLine();
            in = stringIn.charAt(0);
        }
        // 输入数据类型、存放地址、十六进制展示
        String inputType = distinguishService.distinguish(in), toHexadecimal = systemRealService.realHexadecimal(in, inputType);
        // 我的规则二进制展示、十六进制展示
        String myToDecimal = "", myToHexadecimal;
        int inputPlace = systemRealService.realLocation(in);
        System.out.println("实际数据：存储地址"+inputPlace+", 实际十六进制表示："+toHexadecimal);
        if (inputType.equals("Integer")) {
            int intToDecimal = (int) in;
            myToDecimal = myChangeService.intToBinary(intToDecimal);
            if (intToDecimal < 0) {
                myToDecimal = myChangeService.changeBackTwo(myChangeService.changeToByte(myToDecimal));
            }
        } else if (inputType.equals("char")) {
            String charToDecimal = in.toString();
            myToDecimal = myChangeService.intToBinary(charToDecimal.charAt(0));
        } else if (inputType.equals("Float")) {
            float floatToDecimal = (float)in;
            myToDecimal = myChangeService.FloatToBinary(floatToDecimal);
        } else {
            System.out.println("Wrong!");
        }
        String endNum = myChangeService.parseByte2HexStr(myChangeService.changeToByte(myToDecimal));
        System.out.println("我的转换: 二进制表示("+ myToDecimal+ ")   十六进制表示("+ endNum +")");
    }
}
